[FIX] Fix the filtered_programs_for_user
call
#4724
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #4644, the call signature of
filtered_programs_for_user
was changed to replace the functionpublic_programs_for_user
. The goal was to be able to supply the queryget_many({ "username": "henk", "public": 1 })
, with the goal to retrieve all public programs by userhenk
.Unfortunately, there is no index on the pair
(username, public)
. Instead, we have indexes on(username)
and on(public, date)
.The first is used to retrieve all programs by a single user, the second is used to retrieve all public programs (for the "Explore" page). To get the public programs for a single user, instead what we do is retrieve all programs for a single user, and filter them down in Python.
Because of a bug in the database layer, trying to retrieve programs by
{ "username": "henk", "public": 1 }
uses the(public, date)
index. However, the database layer does not detect that in that particular query the fielddate
is missing, and that the fieldusername
is unnecessarily passed. The query incorrectly succeeds in the local database emulation mode so this goes undetected during testing, and when passed to an actual DynamoDB database the server returns an error.This currently breaks the profile page, as well as some other pages probably.
Add
public
as an optional keyword argument tofiltered_programs_for_user
and do the filtering locally instead.How to test
The following pages should work:
/my-profile
/programs
/class/<class_id>/programs/<username>